package com.am.mosl.cityandroid.util;

import android.content.Context;
import android.util.Log;

import com.am.mosl.cityandroid.bean.AccountBean;
import com.am.mosl.cityandroid.bean.Data;

/**
 * Created by mosl on 14-7-10.
 * 设置帮助类，
 */
public class SettingUtils {

    public static final String Usertoken="UserToken";
    public static final String UserName="UserName";
    public static final String UserCity="UserCity";
    public static final String UserGender="UserGender";
    public static final String UserImage="UserImage";
    public static final String IsLogin="IsLogin";
    public static final String Phone="Phone";
    public static final String City_id="city_id";
    

    public static final void saveUserInfo(Context context,AccountBean accountBean){

        PreferencesUtils.putString(context,Usertoken,accountBean.getToken());
        PreferencesUtils.putString(context,UserName,accountBean.data.getName());
        PreferencesUtils.putString(context,UserCity,accountBean.data.getCity());
        PreferencesUtils.putString(context,UserGender,accountBean.data.getSex());
        PreferencesUtils.putString(context,UserImage,accountBean.data.getHead_img());
        PreferencesUtils.putString(context,Phone,accountBean.data.getPhone());
        PreferencesUtils.putString(context,City_id,accountBean.getCity_id());
        PreferencesUtils.putBoolean(context,IsLogin,true);

    }

    public static final boolean IsLogin(Context context){
        boolean isLogin=PreferencesUtils.getBoolean(context,IsLogin);
        return isLogin;
    }

    public static final AccountBean getUserInfo(Context context){

        AccountBean accountBean=new AccountBean();
        Data data=new Data();
        accountBean.setData(data);
        String token=PreferencesUtils.getString(context,Usertoken);
        accountBean.setToken(token);
        String  userName=PreferencesUtils.getString(context,UserName);
        accountBean.data.setName(userName);
        String userCity=PreferencesUtils.getString(context,UserCity);
        accountBean.data.setCity(userCity);
        String userGender=PreferencesUtils.getString(context,UserGender);
        accountBean.data.setSex(userGender);
        String userImage=PreferencesUtils.getString(context,UserImage);
        accountBean.data.setHead_img(userImage);       
        String userPhone=PreferencesUtils.getString(context,Phone);
        accountBean.data.setPhone(userPhone);
        String city_id=PreferencesUtils.getString(context,City_id);
        accountBean.setCity_id(city_id);
        
        return accountBean;

    }


    public static final boolean RemoveAccount(Context context){

        if(!IsLogin(context))
            return false;
        PreferencesUtils.removeKey(context,Usertoken);
        PreferencesUtils.removeKey(context,UserName);
        PreferencesUtils.removeKey(context,UserGender);
        PreferencesUtils.removeKey(context,UserCity);
        PreferencesUtils.removeKey(context,UserImage);
        PreferencesUtils.removeKey(context,IsLogin);
        PreferencesUtils.removeKey(context,Phone);
        PreferencesUtils.removeKey(context,City_id);
        return true;
    }
}
